import { getAction, deleteAction, putAction, putparamsAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"
import { axios as request } from '@/utils/request'

//角色管理
const addRole = (params) => postAction("/sys/role/add", params);
const editRole = (params) => putAction("/sys/role/edit", params);
const checkRoleCode = (params) => getAction("/sys/role/checkRoleCode", params);
const queryall = (params) => getAction("/sys/role/queryall", params);

//用户管理
const addUser = (params) => postAction("/sys/user/add", params);
const editUser = (params) => putAction("/sys/user/edit", params);
const queryUserRole = (params) => getAction("/sys/user/queryUserRole", params);
const getUserList = (params) => getAction("/sys/user/list", params);
const getUserListNotdel = (params) => getAction("/sys/user/selectlist/notdel", params);
const frozenBatch = (params) => putAction("/sys/user/frozenBatch", params);
const getPageList = (params) => getAction("/sys/mgtNotice/getPageList", params);
const updateStatus = (params) => getAction("/sys/mgtNotice/updateStatus", params);
const mgtNoticeDelete = (params) => deleteAction("/sys/mgtNotice/delete", params);
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/sys/user/checkOnlyUser", params);
//改变密码
const changePassword = (params) => putAction("/sys/user/changePassword", params);

//权限管理
const addPermission = (params) => postAction("/sys/permission/add", params);
const editPermission = (params) => putAction("/sys/permission/edit", params);
const getPermissionList = (params) => getAction("/sys/permission/list", params);
const getSystemMenuList = (params) => getAction("/sys/permission/getSystemMenuList", params);
const getSystemSubmenu = (params) => getAction("/sys/permission/getSystemSubmenu", params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params) => getAction("/sys/permission/queryTreeList", params);
const queryTreeListForRole = (params) => getAction("/sys/role/queryTreeList", params);
const queryListAsync = (params) => getAction("/sys/permission/queryListAsync", params);
const queryRolePermission = (params) => getAction("/sys/permission/queryRolePermission", params);
const saveRolePermission = (params) => postAction("/sys/permission/saveRolePermission", params);
const queryPermissionsByUser = () => getAction("/jksaas-mgt/mgt/newSys/permission/getUserPermissionByToken", { menuFlag: 2 });
// const queryPermissionsByUser = () => getAction("/jksaas-mgt/mgt/sys/permission/getUserPermissionByToken", { menuFlag: 2 });
const loadAllRoleIds = (params) => getAction("/sys/permission/loadAllRoleIds", params);
const getPermissionRuleList = (params) => getAction("/sys/permission/getPermRuleListByPermId", params);
const queryPermissionRule = (params) => getAction("/sys/permission/queryPermissionRule", params);

// 部门管理
const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params);
const queryDepartTreeSync = (params) => getAction("/sys/sysDepart/queryDepartTreeSync", params);
const queryIdTree = (params) => getAction("/sys/sysDepart/queryIdTree", params);
const queryParentName = (params) => getAction("/sys/sysDepart/queryParentName", params);
const searchByKeywords = (params) => getAction("/sys/sysDepart/searchBy", params);
const deleteByDepartId = (params) => deleteAction("/sys/sysDepart/delete", params);

//二级部门管理
const queryDepartPermission = (params) => getAction("/sys/permission/queryDepartPermission", params);
const saveDepartPermission = (params) => postAction("/sys/permission/saveDepartPermission", params);
const queryTreeListForDeptRole = (params) => getAction("/sys/sysDepartPermission/queryTreeListForDeptRole", params);
const queryDeptRolePermission = (params) => getAction("/sys/sysDepartPermission/queryDeptRolePermission", params);
const saveDeptRolePermission = (params) => postAction("/sys/sysDepartPermission/saveDeptRolePermission", params);
const queryMyDepartTreeList = (params) => getAction("/sys/sysDepart/queryMyDeptTreeList", params);

//日志管理
const deleteLog = (params) => deleteAction("/sys/log/delete", params);
const deleteLogList = (params) => deleteAction("/sys/log/deleteBatch", params);

//数据字典
const addDict = (params) => postAction("/sys/dict/add", params);
const editDict = (params) => putAction("/sys/dict/edit", params);
const treeList = (params) => getAction("/sys/dict/treeList", params);
const addDictItem = (params) => postAction("/sys/dictItem/add", params);
const editDictItem = (params) => putAction("/sys/dictItem/edit", params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    //console.log("-----------getDictItemsFromCache----------dictCode="+dictCode+"---- dictItems=",dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params) => getAction("/sys/annountCement/doReleaseData", params);
const doReovkeData = (params) => getAction("/sys/annountCement/doReovkeData", params);
//获取系统访问量
const getLoginfo = (params) => getAction("/sys/loginfo", params);
const getVisitInfo = (params) => getAction("/sys/visitInfo", params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/sys/user/queryUserByDepId", params);

// 重复校验
const duplicateCheck = (params) => getAction("/sys/duplicate/check", params);
// 加载分类字典
const loadCategoryData = (params) => getAction("/sys/category/loadAllData", params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend", params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`
//oa流程接口
//查看自定义表单-通过id查询
const getAssembles = (params) => getAction("/formModel/getForm", params);
// /自定义表单-发起流程-获取设置好的流程
const getPreviewProcess = (params) => postAction("/formModel/previewProcess", params);

// 表单提交数据-保存
const saveProcessStart = (params) => postAction("/formData/submit", params);
//根据ID查用户
const getSelectListByIds = (params) => getAction("/sys/user/selectListByIds", params);
///quick-platform任务详情跳转接口-表单数据相关信息
const queryFormData = (params) => getAction("/formData/infoByProcessInstanceId", params);
// 任务详情跳转接口-流程结果
const queryProcessResult = (params) => getAction("/proc/queryActionRecords", params);
// 上传
const addUpload = (params) => postAction("/localfile/localfileMgt/upload", params);
//  同意
const getAgree = (params) => putparamsAction("/procOperation/agree", params);
// 拒绝
const getRefuse = (params) => putparamsAction("/procOperation/refuse", params);
// 根据角色查用户
const getUserRoleList = (params) => getAction("/sys/user/userRoleList", params);
//根据角色查询用户
const getRoleNotContainsMe = (params) => getAction("/proc/UserAndDept/queryUserBatchByRoleNotContainsMe", params);

// 撤销
const getRevoke = (params) => putparamsAction('/procOperation/revoke', params)
//转交
const getPassOn = (params) => putparamsAction('/procOperation/passOn', params)
//加签
const getAddAssignee = (params) => putparamsAction('/procOperation/addAssignee', params)
//退回
const getGoBack = (params) => putparamsAction('/procOperation/goBack', params)
//流程
// const /quick-platform/proc/UserAndDept/queryUserAndDept
// 中转HTTP请求
// 列表移除-表单模型表信息
const removeRecord = (params) => deleteAction("/jktable/head/removeRecord", params);
// 批量
const deleteBatch = (params) => deleteAction("/jktable/head/deleteBatch", params);
// 列表删除-表单模型-删除表信息
const deleteRecord = (params) => deleteAction("/jktable/head/delete", params);
// 同步数据库
const doDbSynch = (params) => postAction(`/jktable/head/doDbSynch/${params.code}/${params.synMethod}`);
// 查询数据表
const queryTables = (params) => getAction("/jktable/head/queryTables", params);
// 导入数据库表-生成表单
// xinzeng
const addOnlineTables = (params) => postAction(`/jktable/head/add`, params);
//
const editAllOnline = (params) => putAction('/jktable/head/editAll', params)

const transTables = (params) => postAction(`/jktable/head/transTables/${params.tbnames}`);

const queryByTable = (params) => getAction("/jktable/head/queryById", params);
//  查找字段通过模型id
const fieldqueryByTable = (params) => getAction("/jktable/field/listByHeadId", params);
// /quick-platform查找索引通过模型id
const indexqueryByTable = (params) => getAction("/jktable/index/listByHeadId", params);
// /quick-platform查找索引通过模型id
const getFileListByIds = (params) => getAction("/sys/common/getFileListByIds", params);

// 查询表单是否开启审批
const getEnableOne = (params) => getAction("/sys/sysEntityProc/getEnableOne", params);
// 查询列表扩展列
// export const queryByEntityCode = (params)=>getAction("/ext/jkEntityExtTable/queryByEntityCode",params);
export function queryByEntityCode(data) {
  return request({
    url: `/ext/jkEntityExtTable/queryByEntityCode?entityCode=${data.entityCode}`,
    method: 'get',
    data
  })
}
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

export {
  mgtNoticeDelete,
  updateStatus,
  getPageList,
  getEnableOne,
  getFileListByIds,
  // imgView,
  // doMian,
  indexqueryByTable,
  fieldqueryByTable,
  queryByTable,
  editAllOnline,
  addOnlineTables,
  transTables,
  queryTables,
  deleteBatch,
  doDbSynch,
  deleteRecord,
  removeRecord,
  getUserListNotdel,
  getUserRoleList,
  getRoleNotContainsMe,
  getPassOn,
  getAddAssignee,
  getGoBack,
  getRevoke,
  getRefuse,
  getAgree,
  addUpload,
  queryProcessResult,
  queryFormData,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  getAssembles,
  getPreviewProcess,
  saveProcessStart,
  getSelectListByIds
}



